const SIDEBAR_STATUS = 'SIDEBAR_STATUS';

const app = {
  state: {
    sidebar: {
      opened: !+sessionStorage.getItem(SIDEBAR_STATUS),
    },
    menus:[],
    version:'v1.2.3',
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {

      if (state.sidebar.opened) {
        sessionStorage.setItem(SIDEBAR_STATUS, 1);
      } else {
        sessionStorage.setItem(SIDEBAR_STATUS, 0);
      }
      state.sidebar.opened = !state.sidebar.opened;

    },
    SET_MENUS: (state, menus) => {
      state.menus = menus;
    },
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      return new Promise(resolve => {
        commit('TOGGLE_SIDEBAR');
        resolve();
      });
    },
    GenerateMenus: ({commit},menus) => {
      return new Promise(resolve => {
        commit('SET_MENUS', menus);
        resolve();
      });
    },
  },
  getters:{
    sidebar: state => state.sidebar,
    menus: state => state.menus,
    version:state => state.version,
  }
};

export default app;
